<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改需求</title>
<base href="<%=basePath%>" />
<link rel="stylesheet" type="text/css" href="css/common.css" />
<link rel="stylesheet" href="<%=basePath%>/js/uploadify/css/uploadify.css" type="text/css"></link>
<link type="text/css" href="js/mcdropdown/css/jquery.mcdropdown.css" rel="stylesheet" media="all" />
<script type="text/javascript" src="js/mcdropdown/lib/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/mcdropdown/lib/jquery.mcdropdown.js"></script>
<script type="text/javascript" src="js/mcdropdown/lib/jquery.bgiframe.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/uploadify/jquery.uploadify-3.1.min.js"></script>
<script language="JavaScript" type="text/javascript" src="<%=basePath%>js/my97/WdatePicker.js" defer="defer"></script>
<script type="text/javascript" src="<%=basePath%>/js/autocomplete/jquery.autocomplete.min.js"></script>
<link rel="Stylesheet" href="<%=basePath%>/js/autocomplete/jquery.autocomplete.css" />
<style type="text/css">
div,fieldset,legend,form,table,tr,td,textarea {margin: 0;padding: 0}
table {margin: 10px 10px;}
td {line-height: 25px;}
input[type="text"] {width: 250px;}
input[type="password"] {width: 250px;}
input[type="textarea"] {width: 250px;}
.divlist {float: left;height: 100%;width: 60%;}
.divcomment {float: left;height: 100%;width: 40%;}
.word{line-height: 120%;word-break:break-all}
</style>

<script type="text/javascript">
	  var reqId = null;  
	  $(document).ready(function(){
			 var brow=$.browser;  
			 if(brow.msie) {
				if( brow.version =='6.0'){
					 $("#uploadset1").css("margin-right","20px");
				};
			 }  
		     $.ajaxSetup ({ cache:false,async: false });
		     //修改需求---------------------------------------------------------------------
		     var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
		     $("#reqForm").submit(function(){
		         $(this).ajaxSubmit(options);
		          return false;
		     });   
		     function beforeSubmit() {
			     if(isEmpty($("#title").val())) { alert("摘要不能为空！"); return false; }
			     return true;
		     }
			 function process(responseJson) {
			     if(responseJson.code == 0) {
			         $('#error_label').text("错误信息：" + responseJson.message);
			         $("#p_error").show();
			         return;
			     }
			     btn_return();
			 }  
			 // 修改需求结束------------------------------------------------------------------
			
			 // 再次提交操作----------------------------------------------------------------------
			 $("#secsubimt").click(function(){
				 edit('submitted');
		     });
			 // 再次提交结束-----------------------------------------------------------------
			 
			 //  归档操作  -----------------------------------------------------------------
			 $("#closed").click(function(){
				 edit('closed');
		      });
			 // 归档操作结束  -----------------------------------------------------------------
			 
	         // 文件上传---------------------------------------------------------------------
		     $("#file_upload").uploadify({   
                  'height'        : 27,    
    	          'width'         : 80,     
    	          'buttonText'    : '添加附件',   
    	          'removeCompleted': true,         //上传完毕上传列表是否去除 
    	          'fileSizeLimit': '50MB',          //上传文件大小设置 单位可以是B、KB、MB、GB 
                  'swf'           : '<%=basePath%>/js/uploadify/uploadify.swf',   
    	          'uploader'      : '<%=basePath%>myreq/upload.do?randomd=' + (new Date()).getTime(),  
    	          'auto'          : false,   
    	          'formData'      : {'reqId':''},  
    	          'fileTypeExts'  : '*.*',   
    	          'onUploadStart' : function(file) {   
    	                $("#file_upload").uploadify("settings","formData", {'reqId':reqId});   
    	           },   
    	          'onUploadSuccess':function(file, data, response){ 
    	        	 // var result = $.parseJSON(data);
	  				 //	if(result.code == 1) {
	  				 //		delRow(row);
	  				 //	} else {
	  				 //		alert(result.msg);
	  				 //	}
			         // $("#fileTable").append("<tr align='center'>"
			         //                     +"<td>"+file.name+"</td>"
			         //                      +"<td>"+file.date+"</td>"
			         //                      +"<td>"+$('#username').val()+"</td>"
			         //                      +"<td width='40px'><a href='http://localhost:8080/cari-oa/myreq/download.do?fileName="+file.name+"'>下载</a></td>"
			         //                      +"<td width='40px'><a href=\'#\' onclick=\'del(this,"+data.id+"); return false;\'>删除</a></td>"
			         //                      +"</tr>");    
			          $('#' + file.id).find('.data').html(' 上传完毕');
			          location.reload();
    	           },   
    	          'onUploadComplete':function(file){   
    	                $('#importLispDialog').window('close');   
    	           },
    	           'onSelectError' : function (file, errorCode, errorMsg) {
		            	if(errorCode == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE)
		            		this.queueData.errorMsg = "不能传空文件!";
		           }
		      });
		     //文件上传结束------------------------------------------------------------------
		     
		     //回复信息----------------------------------------------------------------------
			 $('#commentForm').submit(function(){
				    if(isEmpty($("#comment").val()))
				    { 
				    	alert("回复内容不能为空！"); 
				        return false;
				    }
	                $.ajax({
	                    url: "<%=basePath%>myreq/comment.do",   // 提交的页面
	                    data: $('#commentForm').serialize(),    // 从表单中获取数据
	                    type: "POST",                           // 设置请求类型为"POST"，默认为"GET"
	                    dataType: 'json',
	                    error: function(XMLHttpRequest, textStatus, errorThrown) {
	                          alert(XMLHttpRequest.status);
	                    },
	                    success: function(data) {
	                    	if(data.code == 1) {
	                    		 $("#allComment").prepend(
						    			   "<table style=' width: 83%'>"
						    			 +"   <tr>"
						    			 +"      <td ><label>"+ data.createTime+"</label>"
						    			 +"      &nbsp;&nbsp;&nbsp; <font color='red'>"+$("#usercnname").val()+"</font></td>"
						    			 +"   </tr>"
						    			 +"   <tr>"
						    			 +"      <td class='word' >	<span style='color:#00A;'>"+$("#comment").val()+"</span></td>"
						    			 +"   </tr>"
						    			 +" </table>"
						    	  );
								 $('#comment').val('');
	                        }}
	                    });
	                return false;
	            });
		    //回复信息结束----------------------------------------------------------------------
		     
		    //自动完成加载数据
	        var list = null; 
	        $.post("<%=basePath%>pjcost/project/getProjectByApplyUser.do",{isAll:'false'},function(data){
	        	  list = eval(data);
	        });
	        $("#pName").autocomplete(list,{ 
		        	  max: 12,             //列表里的条目数
		              minChars: 0,         //自动完成激活之前填入的最小字符
		              width: 400,          //提示的宽度，溢出隐藏
		              scrollHeight: 300,   //提示的高度，溢出显示滚动条
		              matchContains: true, //包含匹配，就是data参数里的数据，是否只要包含文本框里的数据就显示
		              autoFill: false,     //自动填充
		        	  formatItem: function(item) { 
			             return item.name; 
			          } 
			     }).result(function(event,item) {   
			          $("#project").val(item.id);
	         }); 
	   });
   
	   function startUpload(){   
		  reqId = $("#reqId").val();
		  if(reqId.replace(/\s/g,'') == '')
		  {
			  alert("reqId不能为空！");   
              return false;    
		  }else
	      {
			  $('#file_upload').uploadify('upload','*');   
	      }
	   }   
	   //修改状态
	   function edit(status)
	   {
		   $.post("<%=basePath%>myreq/edit.do", {id:$("#reqId").val(),sta:status}, function(data) {
				var result = $.parseJSON(data);
				if(result.code == 1) {
					if(status == 'submitted')
					    alert("恢复成功！");
					else if(status == 'close')
						alert("归档成功！");
					else
						alert("操作成功！");
				} else {
					alert(result.msg);
				}
		    });
	   }
	   
	   //删除文件
	   function del(row,id,path) {
			if(confirm("确定删除该文件吗？")) {
				$.get("<%=basePath%>myreq/deleteFile.do", {id:id,path:path}, function(data) {
					var result = $.parseJSON(data);
					if(result.code == 1) {
						delRow(row);
					} else {
						alert(result.msg);
					}
				});
			}
	   }
	   //删除行
	   function delRow(row)   
	   {   
		    $(row).parent("td").parent("tr").remove();   
	   }  
	   
	   //返回列表页面
	   function btn_return(){
		    var qs = $("#qs").val();
	    	window.location.href="<%=basePath%>myreq/list.do?" + qs;
	   }
	</script>
</head>
<body>
	<div class="divlist">
		<div style="width:98%" >
			<fieldset>
				<legend>修改需求：</legend>
				<form id="reqForm" name="reqForm" method="post" action="myreq/edit.do">
					<input id="qs" name="qs" type="hidden" value="${qs}" />
					<p id="p_error" style="margin: 10px 10px;">
						<label id="error_label" style="color: red;"></label>
					</p>
					<table style="table-layout:fixed;overflow:hidden">
						<tr>
							<td width="15%"><label >发起人：</label>
							      <input type="hidden" name="reqId" id="reqId" value="${req.id}">
								  <input type="hidden"  name="id" id="id" value="${req.id}">
								  <input type="hidden"  name="initiator" id="initiator" value="${req.initiator}">
						  		  <input type="hidden"  name="reqType" id="reqType" value="${req.reqType}">
						  		  <input type="hidden"  name="project" id="project" value="${req.project}">
						    </td>
							<td width="80%"><input type="text" id="cnName" name="cnName" value="${sessionScope.usercnname}"
								readonly="readonly" /><font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
						</tr>
						<tr>
							<td><label for="expPerTime">期望完成时间：</label></td>
							<td><input type="text" id="expPerTime" name="expPerTime"
								value="${req.expPerTime}" <c:if test="${req.status =='processed'}"> readonly="readonly"</c:if>
								onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})"
								class="Wdate" /> <font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
						</tr>
						<tr>
							<td><label for="title">标题：</label></td>
							<td><input style="width:460px;"  <c:if test="${req.status =='processed'}"> readonly="readonly"</c:if> type="text" id="title" name="title" style="width:498px;" value="${req.title }" /><font color="red">&nbsp;*&nbsp;&nbsp;</font>
							</td>
						</tr>
						<tr>
							<td><label for="project">所属项目：</label></td>
							<td> 
							   <input id="pName" name="pName" value="${pName}"  style="width:288px;"/><font color="red">（提示：双击可展开下拉列表）</font>
							</td>
				        </tr>
						<tr>
					         <td><label for="status">当前状态：</label></td>
							 <td>
					               <select id="status" name="status" style="width:120px;">
						                <c:forEach var="s" items="${statusList}">
						                    <c:if test="${s.value == req.status}">
						                       <option value="${s.value}">${s.name}</option>
						                    </c:if>
						                </c:forEach>
					               </select>              
					         </td>        
						</tr>
						<tr>
					         <td><label for="status">负责方：</label></td>
							 <td>
							    <select id="startStatus" name="startStatus" style="width:120px;">
					               <c:forEach items="${sList}" var="s" varStatus="status">
					                   <option value="${s.value}" <c:if test="${req.startStatus == s.value}">selected="selected"</c:if>>
					                      ${s.name}
					                   </option>
								   </c:forEach>
							   </select>              
					         </td>        
						</tr>
						<tr>
							<td valign="top"><label for="content">需求内容：</label></td>
							<td valign="top">
							    <textarea <c:if test="${req.status =='processed'}"> readonly="readonly"</c:if> name="content" id="content" cols="63" rows="8"><c:out value="${req.content}"></c:out>
								</textarea>
						    </td>
						</tr>
						<tr>
							<td></td>
							<td>
							    <c:if test="${req.status =='processed'}">
							   		 <input type="button" id="closed" value="归档" style="width: 80px;" /> 
							    </c:if>
							    <c:if test="${req.status =='undone' || req.status =='notPass' }">
							   		 <input type="button" id="secsubimt" value="恢复" style="width: 80px;" /> 
							    </c:if>
							    <c:if test="${req.status !='processed'}">
							     <!-- 	 <c:if test="${req.status =='processing'}"> 
                                	   disabled="disabled"
                                	 </c:if>
                                	 <c:if test="${req.status =='processed'}"> 
                                	   disabled="disabled"
                                	 </c:if> -->
                                	 <input type="submit" id="btn_insert" value="提交" style="width: 80px;" /> 
                                </c:if>
								<input type="button" id="btn_back" value="返回" onclick="btn_return();" style="width: 80px;" />
							</td>
						</tr>
					</table>
				</form>
			</fieldset>
		</div>
		<div id="uploadDiv" style="width:98%;">
				<fieldset id="uploadset1" >
					<legend>上传附件：</legend>
					<input type="file" name="uploadify" id="file_upload" /> <a
						onclick="startUpload();" href="javascript:void(0);">开始上传</a> <a
						href="javascript:$('#file_upload').uploadify('cancel', '*')">取消所有上传</a>
					<hr>
					<table id="fileTable" width="100%">
						<tr  align="center" >
							<th>文件名</th>
							<th>上传时间</th>
							<th>提交人</th>
							<th colspan="3">操作</th>
						</tr>
						<c:forEach  items="${attList}" var="att">
							<tr  align="center" >
								<td>${att.name}</td>
								<td><fmt:formatDate value="${att.createTime}" type="both"
										dateStyle="medium" timeStyle="medium" /></td>
								<td>${att.uploadUser}</td>
								<td width="40px"><a href="<%=basePath%>myreq/download.do?fileName=${att.name}&path=${att.path}">下载</a>
								</td>
					            <td width="40px">  <a href="#" onclick="javascript:del(this,'${att.id}','${att.path}'); return false;">删除</a>	</td>
						  		<td width="40px">
								    <c:forEach items="${pictureFormatList}"
										var="pf">
										<c:if test="${pf == att.type}">
											<a href="${att.path}" class="lightbox" rel="flowers"
												title="${att.name}">预览</a>
										</c:if>
									</c:forEach></td>
							</tr>
						</c:forEach>
					</table>
				</fieldset>
		</div>
	</div>
	<div class="divcomment">
		<fieldset >
			<legend>交流板</legend>
		    <form id="commentForm" >
				<table style="width: 85%">
					<tr>
						<td colspan="2"><textarea name="comment" id="comment" cols="40" rows="5"></textarea></td>
					    <td valign="bottom">
					      <input type="hidden" name="objectId" id="objectId" value="${req.id}">
						  <input type="hidden"  id="usercnname" value="${sessionScope.usercnname}">
					      <input type="submit" id="send" name="send" value="发表" />
					    </td>
					</tr>
				</table>
		    </form>
			<div id="allComment">
			   <c:forEach  items="${comList}" var="com">
					<table>
						<tr>
							<td >
								<label for="project">
								  <fmt:formatDate value="${com.createTime}" type="both"	dateStyle="medium" timeStyle="medium" />
								  	&nbsp;&nbsp;&nbsp;<font color="red">${com.userCnname}</font>
								</label>
							</td>
						</tr>
						<tr>
							<td class="word" >
								<span style="color:#00A;">${com.content}</span>
							</td>
						</tr>
					</table>
				</c:forEach>
			</div>
		</fieldset>
	</div>
</body>
</html>